package com.chinafree.business.controller;

import com.chinafree.auth.model.bo.LoginUserBo;
import com.chinafree.auth.model.result.LoginResult;
import com.chinafree.business.model.param.BaseUserParam;
import com.chinafree.business.model.param.FilesUserParam;
import com.chinafree.business.model.param.ResumeUserParam;
import com.chinafree.business.model.queryCondition.UserQueryCondition;
import com.chinafree.business.model.result.BaseUserResult;
import com.chinafree.business.model.result.CompanyResult;
import com.chinafree.business.model.result.UserBaseMessageResult;
import com.chinafree.business.service.ResumeService;
import com.chinafree.common.model.enumeration.ResponseCodeEnum;
import com.chinafree.common.model.request.RequestParameter;
import com.chinafree.common.model.response.BaseResponse;
import com.chinafree.common.model.response.EntityResponse;
import com.chinafree.common.model.response.ListPagingResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/profile/resume")
public class ResumeController extends BaseController {

    @Autowired
    private ResumeService resumeService;

    @ApiOperation(value = "获得user信息")
    @PostMapping("/getByUserId")
    public EntityResponse<UserBaseMessageResult> getByUserId() {
        return resumeService.getByUserId(getUserId());
    }

    
    @ApiOperation(value = "获得user信息")
    @PostMapping("/getResumeByUserId")
    public EntityResponse<UserBaseMessageResult> getResumeByUserId(@RequestParam("user_id") Long userId) {
        return resumeService.getByUserId(userId);
    }

    @ApiOperation(value = "获得公司信息")
    @PostMapping("/getHRsByCompanyIds")
    private EntityResponse<List<BaseUserResult>> getHRsByCompanyIds() {
        List<BaseUserResult> companyInfo = resumeService.getHRsByCompanyIds();
        return new EntityResponse<>(ResponseCodeEnum.SUCCESS, "查询成功", companyInfo);
    }

    @ApiOperation(value = "编辑BaseUser")
    @PostMapping("/updateBaseUser")
    public BaseResponse updateBaseUser(@RequestBody RequestParameter<BaseUserParam> baseUserParamRequestParameter) {
        if (baseUserParamRequestParameter.getBody() == null) {
            return BaseResponse.failure("数据为空");
        }
        return resumeService.updateBaseUser(baseUserParamRequestParameter.getBody());
    }

    @ApiOperation(value = "编辑BaseUser")
    @PostMapping("/updateUserCompany")
    public EntityResponse<LoginResult> updateUserCompany(
            @RequestBody RequestParameter<String> baseUserParamRequestParameter) {
        if (baseUserParamRequestParameter.getBody() == null) {
            return EntityResponse.failure("数据为空");
        }
        return resumeService.updateUserCompany(baseUserParamRequestParameter.getBody());
    }

    // @ApiOperation(value = "编辑BaseUser")
    // @PostMapping("/insertBaseUser")
    // public BaseResponse insertBaseUser(@RequestBody
    // RequestParameter<BaseUserParam> baseUserParamRequestParameter) {
    // if (baseUserParamRequestParameter.getBody() == null ||
    // baseUserParamRequestParameter.getBody().getId() == null) {
    // return BaseResponse.failure("userId为空");
    // }
    // return resumeService.insertBaseUser(baseUserParamRequestParameter.getBody());
    // }

    @ApiOperation(value = "编辑Resume")
    @PostMapping("/updateResumeUser")
    public BaseResponse updateResumeUser(@RequestBody RequestParameter<ResumeUserParam> baseUserParamRequestParameter) {
        if (baseUserParamRequestParameter.getBody() == null) {
            return BaseResponse.failure("数据为空");
        }
        return resumeService.updateResumeUser(baseUserParamRequestParameter.getBody());
    }

    @ApiOperation(value = "编辑File")
    @PostMapping("/updateFileUser")
    public BaseResponse updateFileUser(
            @RequestBody RequestParameter<List<FilesUserParam>> filesUserParamRequestParameter) {
        return resumeService.updateFileUser(filesUserParamRequestParameter.getBody());
    }

    @ApiOperation(value = "批量查询")
    @PostMapping("/queryUserPage")
    public ListPagingResponse<UserBaseMessageResult> queryUserPage(
            @RequestBody RequestParameter<UserQueryCondition> userQueryCondition) {
        return resumeService.queryUserPage(userQueryCondition.getBody());
    }

    @ApiOperation(value = "简历开启")
    @PostMapping("/setResumeStatus")
    public BaseResponse setResumeStatus(@RequestBody RequestParameter<Byte> filesUserParamRequestParameter) {
        return resumeService.updateResumeStatus(filesUserParamRequestParameter.getBody());
    }
}
